class Solution {
public:
    bool judgeSquareSum(int c) {
        long long tmp = 0;
        long long tt = c;
        while(tmp * tmp <= 2 *tt){
            long long t = tmp*tmp - tt;
            if(t >= 0 && t%2 == 0){
                for(int i = 0;2* i <= tmp;i++){
                    if(i*(tmp - i) * 2 == t)
                        return true;
                    if(i*(tmp - i) * 2 > t)
                        break;
                }
            }
            tmp++;
        }
        return false;
    }
};